#include "comm.h"

Queue* init_queue()
{
	Queue* queue = (Queue *) malloc(sizeof(Queue));
	
	if (queue != NULL) 
	{
		queue->head = NULL;
		queue->tail = NULL;
		queue->size = 0;
	}

	return queue;
}

int get_size(Queue* queue)
{
	return queue->size;
}

int is_empty(Queue* queue)
{
	if ((queue->tail==NULL)&&(queue->tail==NULL)&&(queue->size==0)) 
	{
		return 1;
	}
	else
		return 0;
}

int insert_tail(Queue* queue, const char* node_msg)
{
	queue_node* pnode = (queue_node *) malloc(sizeof(queue_node));
	memset(pnode, 0, sizeof(queue_node));
	
	if (pnode != NULL)
	{
		snprintf(pnode->msg_buf, MSG_BUFFER_LEN, "%s", node_msg);
		snprintf(pnode->insert_time, 50, "%s", node_msg);
		pnode->next = NULL;
		//printf("%s\n", pnode->msg_buff);
		int ret = is_empty(queue);
		if (ret == 1)
		{
			queue->head = queue->tail = pnode;
		}
		else 
		{
			queue->tail = pnode;	
		}

		queue->size ++;
	}
	else 
		return 0;
}

char* pop_front(Queue* queue)
{
	return NULL;
}
